<% metadata_for_verification = SmartContract.get_address_verified_bytecode_twin_contract(@address_hash).verified_contract %>
<% changeset = (if assigns[:retrying], do: @changeset, else: SmartContract.merge_twin_vyper_contract_with_changeset(metadata_for_verification, @changeset)) |> SmartContract.address_to_checksum_address() %>
<section data-page="contract-verification" class="container new-smart-contract-container">
  <%= render BlockScoutWeb.CommonComponentsView, "_channel_disconnected_message.html", text: gettext("Connection Lost") %>

  <div class="new-smart-contract-form">
      <h1 class="smart-contract-title"><%= gettext "New Vyper Smart Contract Verification" %></h1>

      <%= form_for changeset,
          address_contract_verification_path(@conn, :create),
          [],
          fn f -> %>

        <%= render BlockScoutWeb.AddressContractVerificationCommonFieldsView, "_contract_address_field.html", f: f %>

        <%= render BlockScoutWeb.AddressContractVerificationCommonFieldsView, "_contract_name_field.html", f: f, tooltip: "Must match the name specified in the code." %>

        <%= render BlockScoutWeb.AddressContractVerificationCommonFieldsView, "_compiler_field.html", f: f, compiler_versions: @compiler_versions, tooltip: "" %>

        <div class="smart-contract-form-group">
          <div class="smart-contract-form-group-inner-wrapper">
            <%= label f, :contract_source_code, gettext("Enter the Vyper Contract Code") %>
            <div class="center-column">
              <%= textarea f, :contract_source_code, class: "form-control border-rounded monospace", rows: 3, "aria-describedby": "contract-source-code-help-block" %>
              <%= error_tag f, :contract_source_code, id: "contract-source-code-help-block", class: "text-danger form-error", "data-test": "contract-source-code-error" %>
            </div>
            <div class="smart-contract-form-group-tooltip"></div>
          </div>
        </div>

        <%= render BlockScoutWeb.AddressContractVerificationCommonFieldsView, "_constructor_args.html", f: f, display_constructor_arguments_text_area: "block" %>

        <div class="d-none">
          <input type="text" id="verification_type" name="verification_type" value="vyper" />
        </div>

        <div class="smart-contract-form-buttons">
          <button
            class="position-absolute w-118 btn-full-primary d-none mr-2"
            disabled="true"
            id="loading"
            name="button"
            type="button"
          >
            <%= render BlockScoutWeb.CommonComponentsView, "_loading_spinner.html", loading_text: gettext("Loading...") %>
          </button>
          <%= submit gettext("Verify & publish"), class: "btn-full-primary mr-2", "data-button-loading": "animation", "data-submit-button": "" %>
          <%= reset gettext("Reset"), class: "btn-line mr-2 js-smart-contract-form-reset" %>
          <%=
            link(
              gettext("Cancel"),
              class: "btn-no-border",
              to: address_contract_path(@conn, :index, @address_hash)
              )
          %>
        </div>
      <% end %>
    </div>
</section>
